<%@ page language="java" import="java.util.*" pageEncoding="utf-8"
         contentType="text/html; charset=utf-8"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>注册 - 徐二组体育馆网上系统</title>
  <link href=" ${pageContext.request.contextPath}/static/css/nav.css" rel="stylesheet" type="text/css" />
  <script src="${pageContext.request.contextPath}/static/js/nav.js" type="text/javascript"></script>
  <script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
  <script src="${pageContext.request.contextPath}/static/js/focus.js" type="text/javascript"></script>
  <link href=" ${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet" type="text/css" />
  <link href=" ${pageContext.request.contextPath}/static/css/account.css" rel="stylesheet" type="text/css" />
  <script type="text/javascript">
    function selectPhone(userPhone) {
      $.ajax({
        url: "${pageContext.request.contextPath}/user/selectPhone?userPhone="+userPhone,
        success: function(res){
          if(res.indexOf("success") != -1){
            document.getElementById("na").innerHTML="✔";
            document.getElementById("na").style.color="green";
          }else if (res.indexOf("error01") != -1){
            document.getElementById("na").innerHTML="× 格式错误";
            document.getElementById("na").style.color="red";
          }else if (res.indexOf("error02") != -1) {
            document.getElementById("na").innerHTML = "已注册";
            document.getElementById("na").style.color = "red";
          }
        }
      });
    }
    function check(frm) {
      var userName = frm.userName.value;
      var userAge = frm.userAge.value;
      var password = frm.password.value;
      var password1 = frm.password1.value;
      var userSex = frm.userSex.value;
      if (userAge.length==0 || userName.length==0 || password.length==0 ||password1.length==0 || userSex ==0){
        return false;
      }
      if (password != password1) {
        document.getElementById("nf").innerHTML = "不一致,重输";
        return false;
      }
      if (!isNumber1(userAge)) {
        document.getElementById("ag").innerHTML = "请输入数字";
        return false;
      }
      return true;
    }
  </script>
  <script type="text/javascript">
    function isNumber1(str) {
      if(str==null||str.length==0) {return false;}
      for(var i=0;i&lt;str.length;i++) {
        var ch = str.charAt(i);
        if("0123456789".indexOf(ch)==-1) {return false;}//没找到返回-1
      }
      return true;
    }
  </script>


</head>

<body>
<%@ include file="../header.jsp"%>
<div id="main">
  <div id="row_1">
    <div id="reg_banner"><img src="<%=basePath2%>images/login_banner.jpg" /></div>
    <div id="reg_div">
      <form action="${pageContext.request.contextPath}/user/addUser" method="post" onsubmit="return check(this)">
        手&nbsp;机&nbsp;号&nbsp;&nbsp;：
        <input name="userPhone" id="userPhone"   type="text" class="input_text"  onkeyup="selectPhone(this.value)"/>
        <span id="na"></span><br>
        用&nbsp;户&nbsp;名&nbsp;&nbsp;：
        <input name="userName" id="userName" type="text" class="input_text"  />
        <span id="nb" style="color: red;" ></span><br>
        年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄：
        <input name="userAge"  id="userAge" type="text" class="input_text" />
        <span id="nc" style="color: red;" ></span><br>
        性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：
          <label>
            <input type="radio"  name="userSex" value="男">
          </label>男
          <label>
            <input type="radio"  name="userSex" value="女">
          </label>女
        <br/>
        密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：
        <input name="password" id="password" type="password" class="input_text" />
        <span id="ne" style="color: red;" ></span><br>
        确认密码：
        <input name="password1"  id="password1" type="password" class="input_text" />
        <span id="nf" style="color: red;" ></span><br>

        <span id="nw" style="color: red;" ></span><br>
        <p style="color: #761c19">${message}</p>
        <br />
        <input type="submit" value="注册" class="btn" />
        <input type="reset" value="重置" class="btn" />
      </form>
    </div>
  </div>
</div>
<script>
  var def = "1";
</script>
<%@ include file="../footer.jsp"%>
</body>
</html>
